/**
 * author: Hanflyee  flyee1980@163.com
 * vision: v1.0
 * data: 2009-7-9
 */
package com.flyee.service.pool{
	import com.flyee.controller.tools.cartoon.ui.showequip.ShowEquipWindow;
	import com.flyee.model.Charactor;
	import com.flyee.model.MapData;
	import com.flyee.model.Scene;
	import com.flyee.utils.Map;
	import com.flyee.viewer.CharactorViewer;
	import com.flyee.viewer.SceneViewer;
	
	import flash.display.DisplayObjectContainer;
	
	import org.spicefactory.parsley.core.Context;
	
	/**
	 * model和view引用数据池
	 */
	public class ObjectCollection{
		
		public function ObjectCollection(){}
		
		/**默认场景ID*/
		public static var DEFAULT_SCENE_ID : String = "4028810a23dfe2630123dfe8c0520002";
		/**默认装备图板*/
		public static var DEFAULT_USER_ID : String = "4028800f1a4c4944011a4e85e3a50010";
		
		public static var playerVisible : Boolean = true;

		public static var beansContext : org.spicefactory.parsley.core.Context;
				
		/**舞台容器*/
		public static var sceneContainer : DisplayObjectContainer;
		/**舞台容器*/
		public static var uiContainer : DisplayObjectContainer;
		/**M和V的关联数组(RelationMV)*/
		public static var relationArray : Array = new Array();
		//---------------------------------------------------
		/**登陆玩家*/
		public static var master : Charactor;
		/**人物数据MODEL集合*/
		//key为charactor的id
		public static var charactorMap : Map = new Map();
		/**当前场景*/
		public static var currentScene : Scene;
		/**当前场景中的组件*/
		public static var componentMap : Map = new Map();
		/**场景区域数据*/
		public static var mapData : MapData = new MapData();
		//-------------------------------------------------
		/**登陆玩家Viewer*/
		public static var masterViewer : CharactorViewer;
		/**人物Viewer集合*/
		public static var charactorViewerMap : Map = new Map();	
		/**当前场景Viewer*/
		public static var currentSceneViewer : SceneViewer;
		/**当前场景中组件Viewer*/
		public static var componentViewerMap : Map = new Map();
		/**人物寻路定时器集合 key : vid, value : movetimer*/
		public static var moveTimerMap : Map = new Map();
		/**人物动画定时器集合*/
		public static var cartoonTimerMap : Map = new Map();
		//----------------------------------------------------

		//---------------------------------------------------

		//-----------------------------------------------------
		public static var bufferArray : Array;
		//---------------------------------------------------
		public static function getMidsByVid(vid : String) : Array {
			var tmpArr : Array = new Array();
			for each(var relation : RelationMV in relationArray){
				if(relation.vid == vid)
					tmpArr.push(relation.mid);
			}
			return tmpArr;
		}
		
		public static function getMidByVid(vid : String) : String {
			var tmp : String;
			for each(var relation : RelationMV in relationArray){
				if(relation.vid == vid){
					tmp = relation.mid;
					break ;
				}
			}
			return tmp;
		}
		
		public static function getVidsByMid(mid : String) : Array {
			var tmpArr : Array = new Array();
			for each(var relation : RelationMV in relationArray){
				if(relation.mid == mid)
					tmpArr.push(relation.vid);
			}
			return tmpArr;
		}
		
		public static function getVidByMid(mid : String) : String {
			var tmp : String;
			for each(var relation : RelationMV in relationArray){
				if(relation.mid == mid){
					tmp = relation.vid;
					break ;
				}	
					
			}
			return tmp;
		}
		
		public static function getCharacter(id : String) : Charactor {
			if(id == master.gcode) return master;
			for each(var temp : Charactor in charactorMap.values()) {
				if(temp.gcode == id){
					return temp;
				}
			}
			return null;
		}
		
		public static function getCharacterByVid(vid : String) : Charactor{
			if(vid == masterViewer.vid) return master;
			return charactorMap.get(getMidByVid(vid));
		}
		
		public static function getCharacterViewerByMid(mid : String) : CharactorViewer {
			if(mid == master.mid) return masterViewer ;
			return charactorViewerMap.get(getVidByMid(mid));
		}
		
		public static function removeRelationByMid(mid : String) : void {
			for(var i:int=0;i<relationArray.length;i++){
				if(mid==relationArray[i].mid)
					relationArray.splice(i,1); 
			}  
		}
		
		public static function removeRelationByVid(vid : String) : void {
			for(var i:int=0;i<relationArray.length;i++){
				if(vid==relationArray[i].vid)
					relationArray.splice(i,1); 
			} 
		}
		
	}
	
}